let BJBetWagerCount = new Array(17)
for (let i = 0; i < BJBetWagerCount.length; i++) {
    BJBetWagerCount[i] = new Array(17)
}
BJBetWagerCount[1][1] = "1";
BJBetWagerCount[2][1] = "1,2";
BJBetWagerCount[2][2] = "1/2";
BJBetWagerCount[3][1] = "1,2,3";
BJBetWagerCount[3][2] = "1/2,1/3,2/3";
BJBetWagerCount[3][3] = "1/2/3";
BJBetWagerCount[4][1] = "1,2,3,4";
BJBetWagerCount[4][2] = "1/2,1/3,2/3,1/4,2/4,3/4";
BJBetWagerCount[4][3] = "1/2/3,1/2/4,1/3/4,2/3/4";
BJBetWagerCount[4][4] = "1/2/3/4";
BJBetWagerCount[5][1] = "1,2,3,4,5";
BJBetWagerCount[5][2] = "1/2,1/3,2/3,1/4,2/4,3/4,1/5,2/5,3/5,4/5";
BJBetWagerCount[5][3] = "1/2/3,1/2/4,1/3/4,2/3/4,1/2/5,1/3/5,2/3/5,1/4/5,2/4/5,3/4/5";
BJBetWagerCount[5][4] = "1/2/3/4,1/2/3/5,1/2/4/5,1/3/4/5,2/3/4/5";
BJBetWagerCount[5][5] = "1/2/3/4/5";
BJBetWagerCount[6][1] = "1,2,3,4,5,6";
BJBetWagerCount[6][2] = "1/2,1/3,2/3,1/4,2/4,3/4,1/5,2/5,3/5,4/5,1/6,2/6,3/6,4/6,5/6";
BJBetWagerCount[6][3] = "1/2/3,1/2/4,1/3/4,2/3/4,1/2/5,1/3/5,2/3/5,1/4/5,2/4/5,3/4/5,1/2/6,1/3/6,2/3/6,1/4/6,2/4/6,3/4/6,1/5/6,2/5/6,3/5/6,4/5/6";
BJBetWagerCount[6][4] = "1/2/3/4,1/2/3/5,1/2/4/5,1/3/4/5,2/3/4/5,1/2/3/6,1/2/4/6,1/3/4/6,2/3/4/6,1/2/5/6,1/3/5/6,2/3/5/6,1/4/5/6,2/4/5/6,3/4/5/6";
BJBetWagerCount[6][5] = "1/2/3/4/5,1/2/3/4/6,1/2/3/5/6,1/2/4/5/6,1/3/4/5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/6/7/8";
BJBetWagerCount[8][7] = "1/2/3/4/5/6/7,1/2/3/4/5/6/8,1/2/3/4/5/7/8,1/2/3/4/6/7/8,1/2/3/5/6/7/8,1/2/4/5/6/7/8,1/3/4/5/6/7/8,2/3/4/5/6/7/8";
BJBetWagerCount[8][8] = "1/2/3/4/5/6/7/8";
BJBetWagerCount[9][9] = "1/2/3/4/5/6/7/8/9";
BJBetWagerCount[10][10] = "1/2/3/4/5/6/7/8/9/10";
BJBetWagerCount[11][11] = "1/2/3/4/5/6/7/8/9/10/11";
BJBetWagerCount[12][12] = "1/2/3/4/5/6/7/8/9/10/11/12";
BJBetWagerCount[13][13] = "1/2/3/4/5/6/7/8/9/10/11/12/13";
BJBetWagerCount[14][14] = "1/2/3/4/5/6/7/8/9/10/11/12/13/14";
BJBetWagerCount[15][15] = "1/2/3/4/5/6/7/8/9/10/11/12/13/14/15";

const MaxJiangjin = { // 奖金串关限制
    2: 100000,
    3: 100000,
    4: 250000,
    5: 250000,
    6: 500000,
    7: 500000,
    8: 500000
}

// 计算组合数
function ComputeCombineNum(x, y) {
    let FirstValue = 1
    let SecondValue = 1
    if (y > x) {
        return (0)
    } else {
        for (let I = 0; I < y; I++) {
            FirstValue *= x - I
            SecondValue *= I + 1
        }
        let ResultNum = FirstValue / SecondValue
        return (ResultNum)
    }
}

function arrcl(arr, n, z) {
    let r = []
    fn([], arr, n)
    return r

    function fn(t, a, n) {
        if (n === 0 || z && r.length == z) {
            return r[r.length] = t
        }
        for (let i = 0, l = a.length - n; i <= l; i++) {
            if (!z || r.length < z) {
                let b = t.slice()
                b.push(a[i])
                fn(b, a.slice(i + 1), n - 1)
            }
        }
    }
}

function arral(A2, fn) {
    let n = 0
    let codes = []
    let code = []
    let isTest = typeof fn == 'function'
    let stop
    each(A2, n)

    function each(A2, n) {
        if (stop || n >= A2.length) {
            if (isTest && false === fn(code)) {
                stop = true
            } else {
                codes.push(code.slice());
                code.length = n - 1
            }
        } else {
            let cur = A2[n]
            for (let i = 0, j = cur.length; i < j; i++) {
                code.push(cur[i])
                each(A2, n + 1)
            }
            if (n) {
                code.length = n - 1
            }
        }
    }
    return codes
}

function zhuHeGetZuShu(ggWay, zuHe, c) {
    let zhus = 0
    let voteType = GetVotetype(ggWay)
    let voteArr = voteType.split(" ")
    for (let sai = 0, slen = zuHe.length; sai < slen; sai++) {
        let thisZuHe = zuHe[sai]
        for (let v = 0, vlen = voteArr.length; v < vlen; v++) {
            let vVal = voteArr[v]
            let thisBetWagerCount = BJBetWagerCount[c][vVal]
            let thisBetWagerCountArr = thisBetWagerCount.split(",")
            for (let betV = 0, blen = thisBetWagerCountArr.length; betV < blen; betV++) {
                // 计算
                let betZuHeVal = thisBetWagerCountArr[betV]
                let betZuHeArr = betZuHeVal.split("/")
                let zc = 1
                for (let bz = 0, bzlen = betZuHeArr.length; bz < bzlen; bz++) {
                    const el = thisZuHe[Number(betZuHeArr[bz]) - 1]
                    // 计算注数/钱数
                    let thisVal = el.split("-")
                    zc *= Number(thisVal[1])
                    let maxxx = MaxJiangjin[vVal]
                    if (maxxx && zc > maxxx) {
                        zc = maxxx
                    }
                }
                zhus += zc
            }
        }
    }
    return zhus
}

function myCalc(ggWay, sa, sb) {
    let ggArr = ggWay.split("_")
    let c = Number(ggArr[0])
    let macthNum = sa.length + sb.length
    let zuShu = 0
    if (sb.length == 0) {
        if (macthNum > 15 && ComputeCombineNum(sa.length, c) > 100000) {
            return false
        }
        let saZh = arrcl(sa, c)
        for (let i = 0, ilen = saZh.length; i < ilen; i++) {
            let thispl = arral(saZh[i])
            zuShu += zhuHeGetZuShu(ggWay, thispl, c)
        }
    } else {
        // for (let d = minabs; d <= maxabs; d++) {
        const d = sb.length;
        // if (macthNum > 15 && ComputeCombineNum(sb.length, d) > 100000) return false;
        let sbZuHe = arrcl(sb, d)
        let saZuHeVal = c - d
        if (sa.length > 0) {
            if (saZuHeVal >= 0) {
                if (macthNum > 15 && ComputeCombineNum(sa.length, saZuHeVal) > 100000) {
                    return false;
                }
                let saZuHe = arrcl(sa, saZuHeVal);
                if (sbZuHe.length * saZuHe.length > 100000) {
                    return false;
                }
                let temSbZuHe = [];
                for (let sk in sbZuHe) {
                    for (let ak in saZuHe) {
                        temSbZuHe.push(sbZuHe[sk].concat(saZuHe[ak]));
                    }
                }
                sbZuHe = temSbZuHe;
            }
        }
        for (let z = 0, zlen = sbZuHe.length; z < zlen; z++) {
            let thispl = arral(sbZuHe[z]);
            zuShu += zhuHeGetZuShu(ggWay, thispl, c);
        }
        // }
    }
    return zuShu
}

// 串关对照函数
function GetVotetype(typevote) {
    switch (typevote) {
        case "1_1":
            return "1";
        case "2_1":
            return "2";
        case "2_3":
            return "1 2";
        case "3_1":
            return "3";
        case "3_3":
            return "2";
        case "3_4":
            return "2 3";
        case "3_7":
            return "1 2 3";
        case "4_1":
            return "4";
        case "4_2":
            return "2";
        case "4_4":
            return "3";
        case "4_5":
            return "3 4";
        case "4_6":
            return "2";
        case "4_11":
            return "2 3 4";
        case "4_15":
            return "1 2 3 4";
        case "5_1":
            return "5";
        case "5_2":
            return "2";
        case "5_5":
            return "4";
        case "5_6":
            return "4 5";
        case "5_10":
            return "2";
        case "5_16":
            return "3 4 5";
        case "5_20":
            return "2 3";
        case "5_26":
            return "2 3 4 5";
        case "5_31":
            return "1 2 3 4 5";
        case "6_1":
            return "6";
        case "6_2":
            return "2";
        case "6_6":
            return "5";
        case "6_7":
            return "5 6";
        case "6_15":
            return "2";
        case "6_20":
            return "3";
        case "6_22":
            return "4 5 6";
        case "6_35":
            return "2 3";
        case "6_42":
            return "3 4 5 6";
        case "6_50":
            return "2 3 4";
        case "6_57":
            return "2 3 4 5 6";
        case "6_63":
            return "1 2 3 4 5 6";
        case "7_1":
            return "7";
        case "7_7":
            return "6";
        case "7_8":
            return "6 7";
        case "7_21":
            return "5";
        case "7_35":
            return "4";
        case "7_120":
            return "2 3 4 5 6 7";
        case "8_1":
            return "8";
        case "8_8":
            return "7";
        case "8_9":
            return "7 8";
        case "8_28":
            return "6";
        case "8_56":
            return "5";
        case "8_70":
            return "4";
        case "8_247":
            return "2 3 4 5 6 7 8";
        case "9_1":
            return "9";
        case "10_1":
            return "10";
        case "11_1":
            return "11";
        case "12_1":
            return "12";
        case "13_1":
            return "13";
        case "14_1":
            return "14";
        case "15_1":
            return "15";
        default:
            if (typevote.indexOf("二关") > -1)
                return "2";
            if (typevote.indexOf("三关") > -1)
                return "3";
            else
                return "0";
    }
}

export {
    BJBetWagerCount,
    MaxJiangjin,
    ComputeCombineNum,
    arrcl,
    arral,
    myCalc,
    GetVotetype
}